package net.tp.struct.adt;

import java.util.*;

public class SinglyNode<E> {

    public E element;

    public SinglyNode<E> next;

    public SinglyNode(E element, SinglyNode<E> next) {
        this.element = element;
        this.next = next;
    }

    public Iterator<E> iterator() {
        return new Iterator<E>() {
            private SinglyNode<E> curr = SinglyNode.this;
            @Override
            public boolean hasNext() { return curr != null; }
            @Override
            public E next() {
                if (curr == null) throw new NoSuchElementException();
                E next = curr.element;
                curr = curr.next;
                return next;
            }
        };
    }
}
